import axios from 'axios'
import router from '../router'



axios.defaults.baseURL = "http://121.40.135.60:9903"
axios.defaults.headers.post['Content-Type'] = 'application/json';

// 请求拦截 
axios.interceptors.request.use(
    req => {
        const jwtToken = localStorage.getItem('token') //每次发送登录请求之前都在localStorage中拿token
        if(jwtToken) {
            req.headers.Authorization = jwtToken //把token带给后端
        }
        return req
    }
)

// 响应拦截
axios.interceptors.response.use(
    res => {
        if(res.data.code !== 1) {
            return Promise.reject(res)
        }
        return res.data
    }
)

export default axios